#!/usr/bin/env python

import unittest

class Channel:
	""" Asterisk channel class """

	def __init__(self, chan):
		self.channel = chan
	def getName(self):
		return self.channel[self.channel.rfind("/") + 1:self.channel.rfind("-")]
	def getTech(self):
		return self.channel[0:self.channel.rfind("/")]
	def getRandom(self):
		return self.channel[self.channel.rfind("-") + 1:]
	def getUniqueChannel(self):
		return self.channel
	def getChannel(self):
		return self.channel[:self.channel.rfind("-")]


class TestAstpyChannel (unittest.TestCase):
	
	def setUp(self):
		self.channel = Channel("SIP/test-dfe92")
	
	def testGetName(self):
		self.assertEqual(self.channel.getName(), "test")
	def testGetTech(self):
		self.assertEqual(self.channel.getTech(), "SIP")
	def testGetRandom(self):
		self.assertEqual(self.channel.getRandom(), "dfe92")
	def testGetChannel(self):
		self.assertEqual(self.channel.getChannel(), "SIP/test")
	def testGetUniqueChannel(self):
		self.assertEqual(self.channel.getUniqueChannel(), "SIP/test-dfe92")
	
if __name__ == "__main__":
	suite = unittest.TestLoader().loadTestsFromTestCase(TestAstpyChannel)
	res = unittest.TextTestRunner(verbosity=2).run(suite)
